<?php

namespace addons\zzyy\module;

use app\admin\model\zzyy\ZzyyFeature;
use app\admin\model\zzyy\ZzyyRoom;
use app\admin\model\zzyy\ZzyyStore;
use fast\Random;
use think\Db;

class Store
{
    static public function getStoreFormatInfo($id)
    {
        $store = ZzyyStore::get($id);
        if (!$store) {
            return null;
        }

        $count = Db::table('fa_user')->count();
        $store->used_people_num = $count > 100 ?  $count : Random::numeric(2);

        $store->store_bannerimage = cdnurl($store->store_bannerimage, true);
        $store->store_slideimages = (function ($value) {
            $rows = explode(',', $value);
            return array_map(function ($e) {
                return cdnurl($e, true);
            }, $rows);
        })($store->store_slideimages);

        $store->features = (function ($ids) {
            $features = ZzyyFeature::whereIn('id', $ids)->select();
            return array_map(function ($e) {
                return [
                    'id' => $e->id,
                    'title' => $e->feature_name,
                ];
            }, $features);
        })($store->feature_ids);

        return $store;
    }

}